//
//  OMHomeAddressView.m
//  OMENGO
//
//  Created by 梁尚嘉 on 2017/4/19.
//  Copyright © 2017年 Kamfat. All rights reserved.
//

#import "OMHomeAddressView.h"
@interface OMHomeAddressView ()

@property (nonatomic, strong) UIButton *arrowBtn;

@property (nonatomic, assign) BOOL highlighted;

@end

@implementation OMHomeAddressView

- (void)setSelected:(BOOL)selected
{
    _arrowBtn.selected = selected;
}

- (void)setHighlighted:(BOOL)highlighted
{
    _highlighted = highlighted;
    self.addressLabel.highlighted = highlighted;
}

- (void)setAddress:(OMOriginalAddress *)address
{
    _address = address;
    self.addressLabel.text = address.name;
}

- (BOOL)selected
{
    return _arrowBtn.selected;
}

- (instancetype)init
{
    self = [super init];
    [self configure];
    return self;
}

- (void)configure
{
    _addressLabel = [UILabel new];
    _addressLabel.font = SM_CFont(30);
    _addressLabel.textColor = HEXCOLOR(@"#333333");
    _addressLabel.highlightedTextColor = SM_grayColor;
    [self addSubview:_addressLabel];
    [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(@0);
    }];

    _arrowBtn = [UIButton new];
    [_arrowBtn setImage:[UIImage imageNamed:@"address_arrow_down_7x7_"] forState:UIControlStateNormal];
    [_arrowBtn setImage:[UIImage imageNamed:@"address_arrow_up_7x7_"] forState:UIControlStateSelected];
    [self addSubview:_arrowBtn];
    [_arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_addressLabel.mas_right).offset(SM_SIZE(10));
        make.centerY.equalTo(self.mas_centerY);
    }];

    [self setTitle:@"佛山嘉宏酒店公寓"];
}

- (void)setTitle:(NSString *)title
{
    self.addressLabel.text = [NSString stringWithFormat:@"送到：%@",title];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.highlighted = true;
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.highlighted = false;
    UITouch *touch = [touches anyObject];
    CGPoint targetPoint = [touch locationInView:self];
    if (CGRectContainsPoint(self.bounds, targetPoint)) {
        /*
        self.selected = !self.selected;
        if (self.delegate&&[self.delegate respondsToSelector:@selector(didClickAddressView)]) {
            [self.delegate didClickAddressView];
        }
         */
        [OMHUD HUDInfo:@"更多网点建设中"];
    }
}

- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.highlighted = false;
}

@end
